//
//  DDExchangeDetail.m
//  dingdang
//
//  Created by lichq on 7/24/15.
//  Copyright (c) 2015 阮 沧晖. All rights reserved.
//

#import "DDExchangeDetail.h"
#import "UICommonFunc.h"
//#import "UIImageView+AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "DDIntegralExchange.h"
#import "UIViewController+MJPopupViewController.h"
#import "DDExchangeInfoWrite.h"
#import "TOWebViewController.h"

@interface DDExchangeDetail ()
@property (weak, nonatomic) IBOutlet UIImageView *imageV;
@property (weak, nonatomic) IBOutlet UILabel *labName;
@property (weak, nonatomic) IBOutlet UILabel *labScore;
@property (weak, nonatomic) IBOutlet UILabel *labScoreMy;
@property (weak, nonatomic) IBOutlet UIButton *btn;
@property (weak, nonatomic) IBOutlet UILabel *labDetail;
@property (weak, nonatomic) IBOutlet UIButton *imageViewBtn;

@end

@implementation DDExchangeDetail
@synthesize info;
@synthesize delegate;
@synthesize score, scoreMy;

- (void)viewDidLoad {
    NSLog(@"进入到---------->DDExchangeDetail");
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    //[self.imageV setImageWithURL:[NSURL URLWithString:self.info.imgPath] placeholderImage:[UIImage imageNamed:@"个人中心-积分兑换-弹窗奖品图"]];
//    [_imageV sd_setImageWithURL:[NSURL URLWithString:info.imgPath] placeholderImage:[UIImage imageNamed:@"个人中心-积分兑换-弹窗奖品图"] options:SDWebImageRefreshCached];
    [_imageV sd_setImageWithURL:[NSURL URLWithString:info.imgPath] placeholderImage:[UIImage imageNamed:@"个人中心-积分兑换-弹窗奖品图"] options:SDWebImageCacheMemoryOnly];
    _imageViewBtn.contentMode = UIViewContentModeScaleAspectFit;
    //NSURL *url = [NSURL URLWithString:info.imgPath];
    //UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    //UIImageView * imageview = [[UIImageView alloc] initWithImage:image];
    //[_imageViewBtn setImage:image forState:UIControlStateNormal];
    //_imageViewBtn.imageView = imageview;
//    self.imageV.contentMode = UIViewContentModeScaleAspectFit;
    [self.labName setText:self.info.name];
    [self.labScore setText:score];
    [self.labScoreMy setText:scoreMy];
    if ([scoreMy integerValue] < [score integerValue]) {
        [self.btn setTitle:@"财富不足" forState:UIControlStateNormal];
        [self.btn setUserInteractionEnabled:NO];
    }else{
        [self.btn setTitle:@"立即兑换" forState:UIControlStateNormal];
        [self.btn setUserInteractionEnabled:YES];
    }
    
    //[self.btn addTarget:self action:@selector(exchangeAction:) forControlEvents:UIControlEventTouchUpInside];
    

    [self.labDetail setText:self.info.detail];
}

- (void)createUI
{
    self.view.backgroundColor = RGB(245, 245, 245);
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = YES;
    //自定义TAB BAR UI
    [self addNavigatorTitle:NSLocalizedString(@"积分兑换", nil) parent:self.view];
    self.barViewControl.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_Background"]];
    [self AddLeftBtnAction:nil normal:@"top_返回" selected:@"top_返回" action:^{
        //[self dismissViewControllerAnimated:YES completion:nil];
        [self.navigationController popViewControllerAnimated:YES];
    }];
}
- (IBAction)closeAction:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(closeView:)]) {
        [self.delegate closeView:self];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)exchangeAction:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(exchangeNow:)]) {
        [self.delegate exchangeNow:self];
    }
}
- (IBAction)imageViewClicked:(UIButton *)sender {
//    self.info.link = @"www.baidu.com";
    if (!([self.info.link isEqualToString:@""] || self.info.link == nil)) {
        TOWebViewController *web = [[TOWebViewController alloc] initWithURLString:self.info.link];
        web.hidesBottomBarWhenPushed =YES;
        web.hideWebViewBoundaries = YES;
        NSLog(@"nav:%@", self.navigationController);
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:web];
        [self presentViewController:navController animated:YES completion:nil];
    }
}

@end
